home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Networking / ADSP Chat / ADSP Chat.h next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  9.2 KB  |  326 lines  |  [TEXT/MPS ]

  1. /*****************************************************************
  2.  
  3.     Program:    < ADSP Chat >
  4.     File:        < ADSP Char.h >
  5.     
  6.     Written by  Pete Helm, Scott Kuechle
  7.     of <Apple Macintosh Developer Technical Support>
  8.     
  9.     modified by Scott Kuechle
  10.     10/92 SRK Converted from Pascal to C
  11.     8/94 SRK Modified to use a queue of parameter
  12.              blocks.
  13.  
  14.     Copyright © 1992, 1994 Apple Computer, Inc.
  15.     All rights reserved.
  16.     
  17. *****************************************************************/
  18.  
  19.  
  20. #include    <types.h>
  21. #include    <quickdraw.h>
  22. #include    <toolutils.h>
  23. #include    <fonts.h>
  24. #include    <events.h>
  25. #include    <windows.h>
  26. #include    <dialogs.h>
  27. #include    <menus.h>
  28. #include    <desk.h>
  29. #include    <textedit.h>
  30. #include    <scrap.h>
  31. #include    <segload.h>
  32. #include    <osevents.h>
  33. #include    <files.h>
  34. #include    <devices.h>
  35. #include    <memory.h>
  36. #include    <appletalk.h>
  37. #include    <lists.h>
  38. #include    <SysEqu.h>
  39. #include    <Script.h>
  40. #include    <CursorCtl.h>
  41. #include    <Resources.h>
  42. #include    <ADSP.h>
  43. #include    <Packages.h>
  44. #include    <String.h>
  45. #include    <Strings.h>
  46. #include    <Traps.h>
  47. #include    <GestaltEqu.h>
  48.  
  49.  
  50. /*****************************************************************/
  51. /*
  52. /* D A T A  S T R U C T U R E S
  53. /*
  54. /*****************************************************************/
  55.  
  56. typedef struct myDSPParamBlock
  57. {
  58.     long             myA5;            /* save our A5 here */
  59.     ProcPtr            ourCompletion;
  60.     DSPParamBlock     u;
  61. }myDSPParamBlock;
  62.  
  63. typedef myDSPParamBlock myDSPParamBlock;
  64. typedef myDSPParamBlock *myDSPParamBlockPtr;
  65.  
  66.  
  67. typedef short SICN[16];
  68. typedef SICN *SICNList;
  69. typedef SICNList *SICNHand;
  70.  
  71.  
  72. /*****************************************************************/
  73. /*
  74. /* C O N S T A N T S
  75. /*
  76. /*****************************************************************/
  77.  
  78. /* 1.01 - kMinHeap - This is the minimum result from the following
  79.      equation:
  80.             
  81.             ORD(GetApplLimit) - ORD(ApplicZone)
  82.             
  83.      for the application to run. It will insure that enough memory will
  84.      be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  85.      application, and still give the application some 'breathing room'.
  86.      To derive this number, we ran under a MultiFinder partition that was
  87.      our requested minimum size, as given in the 'SIZE' resource. */
  88.      
  89. #define        kMinHeap                (29 * 1024)
  90. #define        kMinSpace                (20 * 1024)
  91.  
  92. #define        _WaitNextEvent            0xA860
  93. #define        _Unimplemented            0xA89F
  94.  
  95. /* For System 7.0 */
  96. #define     _Gestalt                 0xA1AD
  97.  
  98. #define        appleID                    128             /* This is a resource ID */
  99. #define        fileID                     129             /* ditto */
  100. #define        editID                     130             /* ditto */
  101.  
  102.  
  103. #define     extremeNeg                -32768
  104. #define     extremePos                32767 - 1            /* required for old region bug */
  105.  
  106.  
  107.     /*constants for positioning the default item within its box*/
  108. #define        osEvent                    app4Evt        /* event used by MultiFinder */
  109. #define        resumeMask                1            /* bit of message field for resume vs. suspend */
  110. #define        sysEnvironsVersion        1
  111.  
  112. #define        kZonesSize                578            /* size of buffer for zone names */
  113. #define        kGetZoneList            8            /* the Zone Information Protocol socket */
  114. #define        kZIPSocket                6            /* the Zone Information Protocol socket */
  115. #define        kMoreZones                0xFF000000     /* mask to see if more zones to come */
  116. #define        kZoneCount                0x0000FFFF     /* mask to count zones in buffer */
  117. #define        kHilite                    1            /* hilite value for button control */
  118. #define        kDeHilite                0            /* dehilite value for button control */
  119. #define     theBridgeSocket         0x6
  120.  
  121. /* 
  122.  *    constants for window activation 
  123.  */
  124. #define     kActivateWindow            1
  125. #define     kDeactivateWindow        0
  126.  
  127. /* 
  128.  *    A few char codes…
  129.  */
  130. #define     kEnterKey                (char)3            /* enter key */
  131. #define     kReturnKey                (char)13        /* return key */
  132.     
  133. /* size of our adsp send/receive queues */
  134. #define        Qsize                    300
  135.  
  136. #define        kATPTimeOutVal            3            /* re-try ATP SendRequest every 3 seconds */
  137. #define        kATPRetryCount            5            /* for five times */
  138.  
  139. #define        maxZones                250                /* max. zones we can save in our buffer */
  140. #define        ZoneBufSize                maxZones * 33    /* size of our ugly, mondo zone buffer */
  141. #define        BigLookupBuffer            10000            /* another big, ugly buffer - for nbp lookups */
  142. #define        maxNames                250                /* max. names we can save in our buffer */
  143. #define        NameBufSize                maxNames * 33    /* size of our ugly, mondo names buffer */
  144. #define        kLookupBufSize            100
  145.  
  146. #define     rMenuBar                 128                /*application's menu bar*/
  147.  
  148. #define        ZoneMenuID                220                /* zone popup menu */
  149. #define        TypeMenuID                221                /* object type popup menu */
  150. #define        ObjectMenuID            222                /* object popup menu */
  151.  
  152. #define     rAboutDialog              128                /*about alert*/
  153. #define     rDialog                  129                /*application's window*/
  154. #define     rErrorDialog              130                /*error alert window*/
  155.  
  156.     /* The following constants are used to identify menus and their items. The menu IDs*/
  157.     /* have an "m" prefix and the item numbers within each menu have an "i" prefix.*/
  158.  
  159. #define     mApple                  128                    /*Apple menu*/
  160. #define     iAbout                  1
  161.  
  162. #define     mFile                      129                    /*File menu*/
  163. #define     iClose                  1
  164. #define     iQuit                      2
  165.  
  166. #define     mEdit                      130                    /*Edit menu*/
  167. #define     iUndo                      1
  168. #define     iCut                      3
  169. #define     iCopy                      4
  170. #define     iPaste                  5
  171. #define     iClear                  6
  172.  
  173.  
  174. #define     kStandardTriSICN          -3990
  175.  
  176. /* dialog items */
  177.  
  178. #define     kobjectItemID                 1        /* popup menu */
  179. #define     ktypeItemID                  2        /* popup menu */
  180. #define     kzoneItemID                  3        /* popup menu */
  181.  
  182. #define     kRemoteMacsTimeBorderID        4
  183. #define     kRemoteMacsTimeID             5
  184. #define     kConnectButtonID              6        /* connect button */
  185. #define     kQuitButtonID                 7
  186.  
  187. #define     kIncomingMessageBorderID    8
  188. #define        kIncomingTextID             9
  189.  
  190. #define     kOutgoingMessageBorderID    10
  191. #define     kOutgoingTextID             11
  192. #define     kConnectedToString            12
  193.  
  194. #define     kMoofFilterCheckBox            13
  195. #define     kPopupBorderID                14
  196.  
  197.  
  198. #define     kHintText                    15
  199. #define     kRemoteMacsNameID             16
  200.  
  201. #define     kConnectStatusBorder        20
  202. #define     kConnectionStatusString        21
  203.  
  204. /*  our attention codes */
  205.  
  206. #define     kDisplayTime                5
  207. #define     kDisplayTheirName            6
  208.  
  209. #define     maxQElements                30
  210.  
  211. /* our error message codes    */
  212.  
  213. #define     atalkErr                    1
  214. #define     memErr                        2
  215. #define     menuErr                        3
  216. #define     nbpErr                        4
  217. #define     noTargetErr                    5
  218.  
  219. #define     noConnErr                    7
  220. #define     writeNotDoneErr                8
  221. #define     badROMsErr                    9
  222. #define     heapErr                        10
  223. #define     noMemErr                    11
  224. #define     DrvrErr                        12
  225. #define     ListenErr                    13
  226. #define     dspInitErr                    14
  227. #define     dspOpenErr                    15
  228. #define     dspRemoveErr                16
  229.  
  230.  
  231. /*****************************************************************/
  232. /*
  233. /* R O U T I N E S
  234. /*
  235. /*****************************************************************/
  236.  
  237. Boolean doADSPinit(unsigned char *localSocket,
  238.                     short *ccbRefNum,
  239.                     TPCCB ccbPtr);
  240. Boolean setUpADSPbuffers();
  241. void     initializeADSP();
  242. void     FlashReadEnd();
  243. void     FlashReadStart();
  244. void     changeConnectButtonState();
  245. void     DisplayTime();
  246. pascal     void saveThatA5();
  247. pascal     void GetMyTRCCBA5();
  248. pascal     void restoreThatA5();
  249. void     DisplayTheirName();
  250. void     DisplayIncomingText(DSPPBPtr dspPBPtr);
  251. void     removeADSPBuffers();
  252. void     removeConnectionEnd(short ccbRefNum);
  253. Boolean WaitForConnectionRequest();
  254. void     CloseConnection();
  255. pascal     void sendAttnMsgCompRoutine(DSPPBPtr dspPBPtr);
  256. void     sendAttnMsg(DSPPBPtr dspPBPtr,
  257.                  short buffSize,
  258.                  Ptr attnData,
  259.                  short msg,
  260.                  short ccbRefNum);
  261. pascal     void adspOpenRqstCompletionRtn(DSPPBPtr dspPBPtr);
  262. void     sendAnOpenConnReq (DSPPBPtr dspPBPtr,
  263.                         AddrBlock theirAddress,
  264.                         short ccbRefNum);
  265. void     connectToPeer();
  266. pascal     void readIncomingComp(DSPPBPtr dspPBPtr);
  267. void     readIncoming(DSPPBPtr dspPBPtr,
  268.                     short ccbRefNum);
  269. pascal     void writeComp(DSPPBPtr dspPBPtr);
  270. void     writeOutgoing(DSPPBPtr dspPBPtr,
  271.                     short ccbRefNum,
  272.                     Ptr dataPtr,
  273.                     short reqCount);
  274. void     sendTime();
  275. void     sendMyName();
  276. void     signalConnect();
  277. void     checkAttnMsgs();
  278. void     DoConnectionEvents();
  279. void     ADSPLoop();
  280. void     DoPassiveOpen(DSPPBPtr dspPBPtr,
  281.                     short ccbRefNum);
  282. pascal     void OpenPassiveCompletionRtn(DSPPBPtr dspPBPtr);
  283. void     CloseTheConnection(short ccbRefNum);
  284. OSErr     InitQueues();
  285. DSPPBPtr GetQElement(QHdrPtr qHdrPtr);
  286. void     CheckCompletedReads();
  287. void     CheckDoneQueue();
  288. void     ShowADSPError(DSPPBPtr dspPBPtr);
  289. void    SetUpADSPError(OSErr err, StringPtr displayStr);
  290. void     SetOurCompletionRoutine(ProcPtr procPtr,
  291.                             DSPPBPtr dspPBPtr);
  292.  
  293.  
  294. void    Terminate();
  295. void     DialogEditing (short menuItem);
  296. void    DoActivate (WindowPtr window, Boolean becomingActive);
  297. void    CheckEnvirons();
  298. void    drawPopUpTri (WindowPtr whichWindow, Rect r);
  299. void     CopyPstr(Ptr pSource, Ptr pDest);
  300. void     PStrCat(Ptr sourceStr, Ptr destinationStr);
  301. void    DisplayCurrentStatus(Ptr displayStr);
  302. void     ShowError(short index);
  303. void     FatalError(error);
  304. Boolean IsAppWindow(window);
  305. Boolean IsDAWindow(WindowPtr window);
  306. void     DoCloseWindow (WindowPtr window);
  307. void     HiliteConnectButton (short mode);
  308. void     outlinePopUpMenus (WindowPtr whichWindow, Rect r, Str255 itemString);
  309. pascal     void UpdateUserItems (WindowPtr whichWindow, short theItem);
  310. void     DoModeless (DialogPtr whichDialog, short whichItem);
  311. void     setEachUserItem (short item);
  312. void     DoMenuCommand (long menuResult);
  313. void     AdjustMenus();
  314. void     DisposeQueueMemory(QHdrPtr qHdrPtr);
  315. void     Exit(short message);
  316. void     DoIdleProc();
  317. void     AdjustCursor (Point mouse, RgnHandle region);
  318. void     UpdateItemBorder (short item, Rect r);
  319. void     PlotSICN (Rect theRect,SICNHand theSICN, short theIndex);
  320. void     DoEvent (EventRecord event);
  321. void     EventLoop();
  322. Boolean TrapAvailable(tNumber,tType);
  323. void     SetupUserItems();
  324. void     Initialize();
  325. void     zeroOutStrings();
  326.